(function(){

'use strict';

angular.module('controllers.faultLocation.pbossOm')
  .controller('numberMarkController', numberMarkController);

function numberMarkController($scope, pbossOmServer, reponsestate, requeststate, COREDATA) {
  $scope.shoumun = 0;
  $scope.numberMark = requeststate.numberMark;
  pbossOmServer.numberMark(
    function(res) {
      if (res.state === '10000') {
        $scope.items = res.data.pageData;
        Echarts($scope.items);
      }
    }
  );
  //查询条件参数数据类型
  $scope.provinces = COREDATA.PROVINCES;
  $scope.numberMark = {};
  $scope.numberMark.startNumber = 18300000000;
  $scope.numberMark.endNumber = 18300000001;
  $scope.queryAllChannel = function() {
    $scope.shoumun == 1 ? $scope.shoumun = 0 : $scope.shoumun = 1;
    if ($scope.shoumun === 0) {
      pbossOmServer.numberMark(
        function(res) {
          if (res.state === '10000') {
            $scope.items = res.data.pageData;
            Echarts(res.data.pageData);
          }
        }
      );
    }
  };

  var customerEchart = echarts.init(document.getElementById('main'));

  function Echarts(data) {
    var option = {};
    option.series = [];
    option.tooltip = {
      trigger: 'axis'
    };
    option.yAxis = [{
      type: 'value'
    }];
    option.xAxis = [{
      type: 'category',
      data: ['预约号码', '在用号码', '预销户号码', '销户号码', '注销号码', '无效号码', '预占号码', '可用号码']
    }];
    for (var i = 0; i < data.length; i++) {
      option.series.push((chardate(dataFormart(data[i]))))
    }
    customerEchart.setOption(option);

  }

  function chardate(data) {
    return {
      type: 'bar',
      data: data,
      itemStyle: {
        normal: {
          label: {
            show: true,
            position: 'top'
          }
        }
      },
      name: data[data.length - 1],
      barMaxWidth: 13
    };
  };
  /**
   * 格式数据
   */
  function dataFormart(data) {
    var arr = [];
    arr.push(data.reservationNumber - 0);
    arr.push(data.reuseNumber - 0);
    arr.push(data.prepareLogoutUserNumber - 0);
    arr.push(data.logoutUserNumber - 0);
    arr.push(data.logoutNumber - 0);
    arr.push(data.nullityNumber - 0);
    arr.push(data.priorityCardNumber - 0);
    arr.push(data.usableNumber - 0);
    arr.push(data.provinceName);
    return arr;
  }
}
numberMarkController.$inject = ['$scope', 'pbossOmServer', 'reponsestate', 'requeststate', 'COREDATA'];

})();